package com.choichumgming.rentcat.web.controller;


import com.choichumgming.rentcat.common.api.CommonResult;
import com.choichumgming.rentcat.dto.OrderParam;
import com.choichumgming.rentcat.service.OmsBuyerOrderService;
import com.choichumgming.rentcat.service.OmsOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 买家订单管理Controller
 */

@RestController
@Api(tags = "OmsBuyerOrderController",description = "买方订单管理")
@RequestMapping("/buyer")
public class OmsBuyerOrderController {
    @Autowired
    private OmsBuyerOrderService omsBuyerOrderService;
    @Autowired
    OmsOrderService omsOrderService;

    @ApiOperation("根据订单信息生成订单")
    @RequestMapping(value = "/generateOrder",method = RequestMethod.POST)
    @ResponseBody
    public CommonResult generateOrder(@RequestBody OrderParam orderParam){
        return omsBuyerOrderService.generateOrder(orderParam);
    }

    @ApiOperation("支付成功的回调")
    @RequestMapping(value = "/paySuccess",method = RequestMethod.POST)
    @ResponseBody
    public CommonResult paySuccess(@RequestBody Long orderId){
        return omsBuyerOrderService.paySuccess(orderId);
    }

    @ApiOperation("自动取消超时订单")
    @RequestMapping(value = "/cancelTimeOutOrder",method = RequestMethod.POST)
    @ResponseBody
    public Object cancelTimeOutOrder(){
        return omsBuyerOrderService.cancelTimeOutOrder();
    }

    @ApiOperation("取消单个超时订单")
    @RequestMapping(value = "/cancelOrder",method = RequestMethod.POST)
    @ResponseBody
    public CommonResult cancelOrder(Long orderId){
        omsBuyerOrderService.sendDelayMessageCancelOrder(orderId);
        return CommonResult.success("success");
    }


//    订单状态：0->待付款；1->待发货；2->已发货；3->已完成；4->已关闭；5->无效订单
    @ApiOperation("确认收货")
    @RequestMapping(value = "/comfirm/{orderId}",method = RequestMethod.GET)
    @ResponseBody
    public CommonResult updateOrderStatus(@PathVariable("orderId")Long orderId) {
        omsOrderService.updateOrderStatus(orderId, 3);
        return CommonResult.success("成功更新");
    }
    @ApiOperation("根据状态查看所有买家订单")
    @RequestMapping(value = "/list/{userId}",method = RequestMethod.GET)
    @ResponseBody
    public CommonResult list(@PathVariable("userId") Long userId){

        return omsBuyerOrderService.getBuyerList(userId);
    }



}
